package com.siteseat.crudeq.kernel;

import java.io.IOException;

import com.siteseat.crudeq.kernel.exception.InvalidChunkException;

/**
 *
 */
public interface Queue {

  void init() throws Exception;

  void destroy() throws Exception;

  QueueProfile getProfile();

  QueueListener getListener();

  void setListener( QueueListener listener );

  /**
   * @param componentMaybe
   */
  void ensureEnabled();

  /**
   * Gets the enabled
   * 
   * @return the enabled
   */
  boolean isEnabled();

  /**
   * Sets the enabled
   * 
   * @param enabled
   *          the enabled to set
   */
  void setEnabled( boolean enabled );

  /**
   * @return
   */
  long getFirstChunkId();

  /**
   * @param chunkId
   * @param offset
   * @return
   * @throws InvalidChunkException
   */
  MessageHistory history( MessageId msgId ) throws InvalidChunkException;

  /**
   * @param message
   */
  void commit( Message msg );

  /**
   * @param message
   */
  void rollback( Message msg );

  /**
   * @param messageSize
   * @return
   * @throws IOException
   * @throws InterruptedException
   */
  Message prepare( int messageSize ) throws InterruptedException, IOException;

}